import { Button, Tooltip, message } from 'antd';
import { ColumnsRenderFun, renderFileFunc } from '../../Acommon';
import { PlusCircleOutlined, DeleteOutlined, EyeOutlined } from '@ant-design/icons';
import { BZWC_STATE } from '../common/Format';
import { readReadShowFileService } from '@/services/BaseLayout';
import { getBaseUrl } from '@/services/urlconst';
import { downloadTemplate, getFileNameNotType, splitFileUrl } from '@/utils';
import MyIcon from '@/components/MyIcon';

interface getPackTableColumnsState {
  onOpenReadOfdWord: (url: string) => void;
  onRemovePack: (index: number) => void;
  pageType: string;
  isType: string;
  infoObj: Record<string, any>;
  curRes: Record<string, any>;
}

/**
 * @getPackModalTableColumns 招标公告标包谈弹窗列表配置
 * @returns
 */
export const getPackModalTableColumns = (): Record<string, any>[] => {
  return [
    {
      title: '包号',
      dataIndex: 'packCode',
      key: 'packCode',
      width: 80,
      render: (text: string) => ColumnsRenderFun({ text }),
    },
    {
      title: '包名称',
      dataIndex: 'packName',
      key: 'packName',
      width: 150,
      render: (text: string) => ColumnsRenderFun({ text, isTooltip: true }),
    },
    {
      title: '预算金额（元）',
      dataIndex: 'expectSum',
      key: 'expectSum',
      width: 150,
      visible: true,
      render: (text: string) => {
        return Number(text).toFixed(2);
      },
    },
    {
      title: '最高限价（元）',
      dataIndex: 'expectCeilSum',
      key: 'expectCeilSum',
      width: 150,
      visible: true,
      render: (text: string) => {
        return Number(text).toFixed(2);
      },
    },
  ];
};
/**
 * @getPackTableColumns 招标公告标包列表配置
 * @returns
 */
export const getPackTableColumns = ({
  onOpenReadOfdWord,
  onRemovePack,
  pageType,
  isType,
  infoObj,
  curRes,
}: getPackTableColumnsState): Record<string, any>[] => {
  let columnsConfig = [
    {
      title: '包号',
      dataIndex: 'packCode',
      key: 'packCode',
      width: 100,
      visible: true,
      render: (text: string) => ColumnsRenderFun({ text }),
    },
    {
      title: '包名称',
      dataIndex: 'packName',
      key: 'packName',
      width: 100,
      visible: true,
      render: (text: string) => ColumnsRenderFun({ text, isTooltip: true }),
    },
    {
      title: '正式采购文件',
      dataIndex: 'busiFileURL',
      key: 'busiFileURL',
      width: 100,
      visible: true,
      render: (_: string, record) => {
        return (
          <>
            {renderFileFunc({ record, fileName: 'busiFileURL', downloadAddress: '/purchaseSourcePrepareController/downloadFile' })}
            {/* 轻阅读预览 */}
            <Tooltip title={'在线预览'}>
              <Button type="link" size="small" onClick={() => onOpenReadOfdWord(record?.busiFileURL)} icon={<EyeOutlined />} />
            </Tooltip>
          </>
        );
      },
    },
    {
      title: '预算金额（元）',
      dataIndex: 'expectSum',
      key: 'expectSum',
      width: 100,
      visible: true,
      render: (text: string) => {
        return Number(text).toFixed(2);
      },
    },
    {
      title: '最高限价（元）',
      dataIndex: 'expectCeilSum',
      key: 'expectCeilSum',
      width: 100,
      visible: true,
      render: (text: string) => {
        return Number(text).toFixed(2);
      },
    },
    {
      title: <div style={{ textAlign: 'center' }}>操作</div>,
      dataIndex: 'operation',
      key: 'operation',
      width: 50,
      visible: isType === 'edit' ? false : true,
      // visible: true,
      unDrag: true,
      fixed: 'right',
      render: (_: string, __: Record<string, any>, index: number) => {
        return (
          <div style={{ textAlign: 'center' }}>
            <Button danger type={'link'} size={'small'} className="manageBtntTxtStyle" icon={<DeleteOutlined />} onClick={() => onRemovePack(index)}>
              删除
            </Button>
          </div>
        );
      },
    },
    // {
    //   title: (
    //     <div style={{ textAlign: 'center' }}>
    //       <Button type={'link'} size={'small'} icon={<PlusCircleOutlined />} className="manageBtntTxtStyle">
    //         操作
    //       </Button>
    //     </div>
    //   ),
    //   dataIndex: 'operation',
    //   key: 'operation',
    //   width: 50,
    //   visible: isType === 'edit' ? false : true,
    //   // visible: true,
    //   unDrag: true,
    //   fixed: 'right',
    //   render: (_: string, __: Record<string, any>, index: number) => {
    //     return (
    //       <div style={{ textAlign: 'center' }}>
    //         <Button danger type={'link'} size={'small'} className="manageBtntTxtStyle" icon={<DeleteOutlined />} onClick={() => onRemovePack(index)}>
    //           删除
    //         </Button>
    //       </div>
    //     );
    //   },
    // },
  ];

  if (infoObj?.state == BZWC_STATE() && !infoObj?.noticeCode && curRes?.['/purchaseSourceController/addBid'] && isType === 'add') {
    columnsConfig = columnsConfig;
  } else {
    columnsConfig = columnsConfig?.filter((item: any) => item?.key != 'operation');
  }

  return columnsConfig;
};
/**
 * @getProjectModalTableColumns 招标公告采购项目弹窗列表配置
 * @returns
 */
export const getProjectModalTableColumns = (): Record<string, any>[] => {
  return [
    {
      title: '采购项目名称',
      dataIndex: 'projectName',
      key: 'projectName',
      width: 180,
      render: (text: string) => ColumnsRenderFun({ text, isTooltip: true }),
    },
    {
      title: '采购项目编号',
      dataIndex: 'projectCode',
      key: 'projectCode',
      width: 180,
      render: (text: string) => ColumnsRenderFun({ text, isTooltip: true }),
    },
    {
      title: '承办单位',
      dataIndex: 'organizer',
      key: 'organizer',
      width: 150,
      visible: true,
      render: (text: string) => ColumnsRenderFun({ text, isTooltip: true }),
    },
    {
      title: '联系人',
      dataIndex: 'contacts',
      key: 'contacts',
      width: 150,
      visible: true,
      render: (text: string) => ColumnsRenderFun({ text }),
    },
    {
      title: '电话',
      dataIndex: 'phone',
      key: 'phone',
      width: 150,
      visible: true,
      render: (text: string) => ColumnsRenderFun({ text }),
    },
    {
      title: '采购申请名称',
      dataIndex: 'applyName',
      key: 'applyName',
      width: 180,
      visible: true,
      render: (text: string) => ColumnsRenderFun({ text, isTooltip: true }),
    },
  ];
};
